<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <div id="map">
    </div>
    <script>
        var map = new ol.Map({
            target: "map",
            layers: [gaode],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        /* 标注是基于点要素去构建的 */
        /* 设置标注样式 */
        // 二. 通过Style类创建icon
        const style = new ol.style.Style({
            /**{olx.style.IconOptions}类型*/
            image: new ol.style.Icon({
                anchor: [0.5, 0.5],
                // anchorOrigin: 'top-right',
                anchorOrigin: 'top-left',
                anchorXUnits: 'fraction',// 比例（分数，小数）
                anchorYUnits: 'fraction',// 像素// pixels
                // offsetOrigin: 'top-right',
                offsetOrigin: 'top-left',
                // offset:[10,10],
                //图标缩放比例
                scale: 0.5,
                //透明度
                opacity: 0.75,
                //图标的url
                src: '/images/location.png',
            }),
        })
        map.on('click', (e) => {
            // console.log(e)
            const coordinate = e.coordinate //[x,y]
            const point = new ol.Feature({
                geometry: new ol.geom.Point(coordinate),
            })
            source.addFeature(point)
        })

        /* layer-source */
        let source = new ol.source.Vector({

        })

        let layer = new ol.layer.Vector({

        })
        layer.setStyle(style)
        layer.setSource(source);
        layer.setMap(map);
    </script>
</body>

</html>